﻿import QtQuick 2.0
import QtQuick.Window 2.12

Item {
//    FontLoader{
//        id: fontLoader
//        source: "qrc:/AlibabaPuHuiTi-3-55-Regular.ttf"
//    }


    property real dpScale: 1.5
    property real dp_density: Math.max(Math.min(Screen.pixelDensity * 0.15 * dpScale, 1.3), 0.5)
    property real dp_pixel: Screen.width / 1700

//    onDpChanged: {

//        console.log("当前Dp------------->", dp, dp_density, dp_pixel, Screen.pixelDensity, Screen.width)
//    }

//    Timer{
//        id: timer_changeDp
//        repeat: true
//        interval: 1000
//        onTriggered: {
//            console.log(Screen.pixelDensity, Screen.width)
//        }
//    }
//    Component.onCompleted: {
//        timer_changeDp.start()
//    }

    property real dp: Math.min(dp_pixel, dp_density)
//    property real dp: dp_density
    property int fontsize: 15 * dp

    property int device: 0          // [0]PC [1]安卓(会禁用Hover样式)
    property bool hoverEnabled:  device === 0

    property color themeColor: "#1677FF"
    property color themeColor_light1: lightColor(themeColor)
    property color themeColor_light2: "#F2F9FF"
    property color themeColor_deep: deepColor(themeColor)

    property color redColor: "#F56C6C"
    property color greenColor: "#67C23A"
    property color blueColor: "#2787FC"
    property color yellowColor: "#E6A23C"

    function lightColor(color){
        var weight = color.r+color.g+color.b
        let r = Math.min(255, color.r*255 + 30 + weight*30*(1-color.r))
        let g = Math.min(255, color.g*255 + 30 + weight*30*(1-color.g))
        let b = Math.min(255, color.b*255 + 30 + weight*30*(1-color.b))
        return Qt.rgba(r/255, g/255, b/255, color.a)
    }
    function lightColor2(color){
        var weight = color.r+color.g+color.b
        let r = Math.min(255, color.r*255 + 30 + weight*100*(1-color.r))
        let g = Math.min(255, color.g*255 + 30 + weight*100*(1-color.g))
        let b = Math.min(255, color.b*255 + 30 + weight*100*(1-color.b))
        return Qt.rgba(r/255, g/255, b/255, color.a)
    }

    function deepColor(color){
        let r = Math.max(0, color.r*255 - 30 * (1.2-color.r))
        let g = Math.max(0, color.g*255 - 30 * (1.2-color.g))
        let b = Math.max(0, color.b*255 - 30 * (1.2-color.b))
        return Qt.rgba(r/255, g/255, b/255, color.a)
    }
    function deepColor2(color){
        let r = Math.max(0, color.r*255 - 30 * (1.6-color.r))
        let g = Math.max(0, color.g*255 - 30 * (1.6-color.g))
        let b = Math.max(0, color.b*255 - 30 * (1.6-color.b))
        return Qt.rgba(r/255, g/255, b/255, color.a)
    }

    function getOpacityColor(color, opacity){
        let r = Math.max(0, color.r)
        let g = Math.max(0, color.g)
        let b = Math.max(0, color.b)
        return Qt.rgba(r, g, b, opacity)
    }

    function reverseStepColor(color){       // 返回黑色或者白色
        var weight = color.r + color.g + color.b
        if(weight > 2.3 || color.a * (4-weight) < 1){
            return Qt.rgba(0.1, 0.1, 0.1, 1)    // 黑色
        }else{
            return Qt.rgba(1, 1, 1, 1)          // 白色
        }
    }

}
